package beans.mybatis.user.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hfy.model.po.user.post.PostDataPo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;


/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 韩
 * @since 2025-03-08
 */
@DS("user")
public interface PostDataMapper extends BaseMapper<PostDataPo> {
    @DS("user")
    @Select("SELECT post_id postId, heat FROM `post_data`, post WHERE post_id = post.id")
    List<PostDataPo> getHeatList();

    /**
     * 根据内容文本查找帖子ID
     */
    @Select("SELECT post_id FROM post_data WHERE content_text LIKE CONCAT('%', #{contentText}, '%')")
    List<Integer> findPostIdsByContentText(@Param("contentText") String contentText);

    /**
     * 根据帖子ID列表查询帖子数据
     */
    @Select("<script>" +
            "SELECT * FROM post_data WHERE post_id IN " +
            "<foreach collection='postIds' item='id' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            "</script>")
    List<PostDataPo> selectByPostIds(@Param("postIds") List<Integer> postIds);

    /**
     * 更新帖子热度
     */
    @Update("UPDATE post_data SET heat = #{heat} WHERE post_id = #{postId}")
    int updateHeat(@Param("postId") Integer postId, @Param("heat") Integer heat);
}

